<?php

include 'adminfunc.php';
include '../func/sql.php';
include '../func/check.php';

session_start();

if(isset($_SESSION['loggedin'])){
	if(isset($_POST['name']) && isset($_POST['sn'])){
		$name = $_POST['name'];
		$sn = $_POST['sn'];
		if(isSN($sn)){
			$date = getdate();
			$date = $date[0];
			
			$e = addMember($name,$sn,$date);
			switch($e){
				case 0:
					//ERROR
					header("Location: index.php?addmember&error=0");
				break;
				case 1:
					//SUCCESS
					header("Location: index.php?addmember&suc=1&name=" . $name . "&sn=" . $sn);
				break;
				case 2:
					//IS MEMBER
					header("Location: index.php?addmember1&error=1");
				break;
			}
		}else{
			header("Location: index.php?addmember&error=3");
		}
	}else{
		header("Location: index.php?addmember&error=2");
	}
}else{
	header("Location: index.php");
}

?>
